﻿/**

 @Name：layuiAdmin 用户管理，增删改查
 @Author：马达
 @Site：http://www.sunplus.wang
 @License: 杭州九宸智能科技有限公司
    
 */

layui.define(['table', 'form', 'laydate', 'upload', 'admin'], function (exports) {
    var $ = layui.$
        , admin = layui.admin
        , view = layui.view
        , table = layui.table
        , upload = layui.upload
        , laydate = layui.laydate
        , form = layui.form;

    var varButtonRight = "";
    //文章管理
    table.render({
        elem: '#LAY-app-content-list'
        , toolbar: false  //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
        , defaultToolbar: ['filter']
        , method: "post"
        , url: layui.setter.APIUrl + '/shop/order_deliverMgr/listPain'
        , headers: { //通过 request 头传递
            Authorization: "bearer " + layui.data('layuiAdmin').access_token
        }
        , parseData: function (res) { //res 即为原始返回的数据 
            varButtonRight = res.Data.ButtonRight;
            return {
                "ResultCode": res.ResultCode, //解析接口状态
                "ResultInfo": res.ResultInfo, //解析提示文本
                "count": res.Data.TotalRecordCount, //解析数据长度
                "Data": res.Data.Items //解析数据列表 
            };
        }
        , cols: [[
            //{ type: 'checkbox', fixed: 'left', field: 'PID' }, //sort: true  //hide: true //  width:100
            //{ field: 'OrderID_SelSource', title: '订单ID'},
            {
                field: 'OrderID_SelSourceName', title: '订单号<br/>发货单号', minWidth: 150, templet: function (d) {
                    var str = "";
                    str += "<span style=''>" + d.OrderID_SelSourceName + "</span>";
                    str += "<br/>";
                    str += "<span style=''>" + d.DeliveyNumber + "</span>";
                    return str;
                }
            },
            {
                field: 'User_SelSourceName', title: '下单人<br/>会员编号', minWidth: 130, templet: function (d) {
                    var str = "";
                    str += "<span style=''>" + d.User_SelSourceName + "</span>";
                    str += "<br/>";
                    str += "<span style=''>" + d.MemberCode + "</span>";
                    return str;
                }
            },
            {
                field: 'UserName', title: '联系人<br/>联系电话', minWidth: 130, templet: function (d) {
                    var str = "";
                    str += "<span style=''>" + d.UserName + "</span>";
                    str += "<br/>";
                    str += "<span style=''>" + d.UserTel + "</span>";
                    return str;
                }
            },
            {
                field: 'SendUser_SelSourceName', title: '发货人<br/>发货时间', minWidth: 130, templet: function (d) {
                    var str = "";
                    str += "<span style=''>" + d.SendUser_SelSourceName + "</span>";
                    str += "<br/>";
                    str += "<span style=''>" + d.DeliverTime + "</span>";
                    return str;
                }
            },
            {
                field: 'TagEnd', title: '发货终端', minWidth: 130, templet: function (d) {
                    var str = "";
                    if (d.TagEnd == 1) {
                        str += "<span class='bksp'>供应商</span>";
                    } else {
                        str += "<span class='bksp1'>网点</span>";
                    }
                    str += "<br/>";
                    str += "<span style=''>" + d.TagEndIDName + "</span>";
                    return str;
                }
            },
	    	{
	    	    field: 'OrderPrice', title: '订单金额', width: 100, templet: function (d) {
	    	        var html = "<span style='color:#FF5722;font-weight:bold;'>￥</span><span style='color:#FF5722;font-weight:bold;font-size:1.1em'>" + d.OrderPrice + "</span>";
	    	        return html;
	    	    }
	    	},
            {
                field: 'DistributionMode', title: '订单配送方式', width: 120, templet: function (d) {
                    var btnText = "";
                    if (d.DistributionMode == 1) {
                        btnText += "<span style='color:#1E9FFF;font-weight:bold'>快递</span>";
                    } else {
                        btnText += "<span style='color:#483D8B;font-weight:bold'>自提</span>";
                    }
                    return btnText;
                }
            },
	    	{
	    	    field: 'DeliverType', title: '发货类型', width: 120, templet: function (d) {
	    	        var btnText = "";
	    	        if (d.DeliverType == 0) {
	    	            btnText += "<span style='color:#1E9FFF;font-weight:bold'>邮寄发货</span>";
	    	        } else if (d.DeliverType == 1) {
	    	            btnText += "<span style='color:#483D8B;font-weight:bold'>自提发货</span>";
	    	        } else if (d.DeliverType == 2) {
	    	            btnText += "<span style='color:#FF8C00;font-weight:bold'>核销发货</span>";
	    	        } else {
	    	            btnText += "<span style='color:#ADD8E6;font-weight:bold'>其他发货</span>";
	    	        }
	    	        return btnText;
	    	    }
	    	},
            {
                field: 'ExpressNumber', title: '快递信息', templet: function (d) {
                    var ExpressNumber = "";
                    var ExpressName = "";
                    if (d.DeliverType == 0) {
                        ExpressNumber = d.ExpressNumber;
                        ExpressName = d.ExpressName + "(" + d.ExpressCode + ")";
                    } else {
                        return "";
                    }
                    var str = "";
                    str += "<span style=''>快递单号：" + ExpressNumber + "</span>";
                    str += "<br/>";
                    str += "<span style=''>快递公司：" + ExpressName + "</span>";
                    return str;
                }, minWidth: 130
            },
            {
                title: '操作', width: 90, fixed: 'right', align: 'center', templet: function (d) {
                    var strRtn = "";
                    if (varButtonRight.indexOf('view') >= 0) {
                        strRtn += "<a class=\"layui-btn layui-btn-primary layui-btn-xs\" lay-event=\"view\">查看</a> ";
                    }
                    if (varButtonRight.indexOf('edit') >= 0) {
                        strRtn += "<a class=\"layui-btn layui-btn-normal layui-btn-xs\" lay-event=\"edit\">编辑</a> ";
                    }
                    if (varButtonRight.indexOf('del') >= 0) {
                        strRtn += "<a class=\"layui-btn layui-btn-danger layui-btn-xs\" lay-event=\"del\">删除</a> ";
                    }
                    return strRtn;
                }
            }

        ]]
        , page: true
        , limit: 10
        , limits: [10, 15, 20, 25, 30]
        , text: {
            none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增 text: '对不起，加载出现异常！'
        }
    });

    //监听工具条
    table.on('tool(LAY-app-content-list)', function (obj) {
        //debugger;
        var data = obj.data;
        if (obj.event === 'del') {
            layer.confirm('确定删除吗？', function (index) {
                admin.req({
                    url: layui.setter.APIUrl + '/shop/order_deliverMgr/BatchDelete' //实际使用请改成服务端真实接口
                    , data: { "ids": data.PID }
                    , type: "post"
                    //, success: function (res) {
                    //}
                    , done: function (res) {
                        layer.close(index); //执行关闭 
                        table.reload('LAY-app-content-list');
                        layer.msg('删除成功');
                    }
                });
            });
        }
        else if (obj.event === 'edit') {
            //location.hash = '/shop/shop_order_deliver/addChild/id=' + data.PID;
            admin.popup({
                title: '编辑信息'
                , area: ['850px', '650px']
                , id: 'LAY-popup-content-edit'
                , success: function (layero, index) {
                    view(this.id).render('/shop/shop_order_deliver/add', data).done(function () {
                        form.render(null, 'layuiadmin-app-form-list');

                        //监听提交
                        form.on('submit(layuiadmin-app-form-submit)', function (data) {
                            var field = data.field; //获取提交的字段 
                            //提交 Ajax 成功后，关闭当前弹层并重载表格 
                            admin.req({
                                url: layui.setter.APIUrl + '/shop/order_deliverMgr/update' //实际使用请改成服务端真实接口
                                , data: field
                                , type: "post"
                                , done: function (res) {
                                    layui.table.reload('LAY-app-content-list'); //重载表格
                                    layer.close(index); //执行关闭
                                    layer.msg('修改成功');
                                }
                            });
                        });
                    });
                }
            });
        }
        else if (obj.event === 'view') {
            admin.popup({
                title: '查看信息'
                , area: ['80%', '90%']
                , id: 'LAY-popup-content-view'
                , success: function (layero, index) {
                    view(this.id).render('/shop/shop_order_deliver/view', data).done(function () {
                        //监听提交
                        form.on('submit(layuiadmin-app-form-submit)', function (data) {
                            layer.close(index); //执行关闭
                        });
                    });
                }
            });
        }
    });

    exports('shop_order_deliver', {})

});
